/**
 * Copyright (C) 2017 - 2020 https://github.com/joewee
 * <p>
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * <p>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.bifrost.workflow.inventory.extension;

import com.bifrost.entity.Product;
import com.bifrost.entity.ProductSku;
import com.bifrost.exception.InventoryUnavailableException;
import com.bifrost.extension.ExtensionHandler;
import com.bifrost.extension.ExtensionResultHolder;
import com.bifrost.extension.ExtensionResultStatusType;

import java.util.Collection;
import java.util.Map;

/**
 * @author joewee
 * @version 1.0.0
 * @Date 2017/11/17 20:25
 */
public interface InventoryServiceExtensionHandler extends ExtensionHandler {


    public ExtensionResultStatusType retrieveQuantitiesAvailable(Collection<ProductSku> skus, Map<String, Object> context, ExtensionResultHolder<Map<ProductSku, Integer>> result);


    public ExtensionResultStatusType decrementInventory(Map<ProductSku, Integer> skuQuantities, Map<String, Object> context) throws InventoryUnavailableException;


    public ExtensionResultStatusType incrementInventory(Map<ProductSku, Integer> skuQuantities, Map<String, Object> context);

    /**
     * Usually invoked via the OMS to determine how to handle a change order.
     *
     * @param decrementSkuQuantities
     * @param incrementSkuQuantities
     * @param context
     * @return
     * @throws InventoryUnavailableException
     */
    public ExtensionResultStatusType reconcileChangeOrderInventory(Map<ProductSku, Integer> decrementSkuQuantities, Map<ProductSku, Integer> incrementSkuQuantities, Map<String, Object> context) throws InventoryUnavailableException;

    /**
     * Usually invoked via the AdvancedProduct to determine the availability of product bundle.
     *
     * @param product  contains Product
     * @param quantity
     * @param holder
     */
    ExtensionResultStatusType isProductBundleAvailable(Product product, int quantity, ExtensionResultHolder<Boolean> holder);
}

